/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * mainForm.java
 *
 * Created on 04/09/2009, 16:47:30
 */
package GUI;

import baseObjects.Language;
import baseObjects.Symbol;
import baseObjects.XML_Handler;
import corpus.Indexer;
import corpus.Observer;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import java.io.*;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Vector;
import java.util.concurrent.TimeUnit;
import javax.swing.JProgressBar;
import javax.swing.JScrollBar;
import pipeline.KeyboardCandidate;
import pipeline.KeyboardConsumer;
import pipeline.KeyboardProducer;
import pipeline.SynchronizedBuffer;
import pipeline.TopBuffer;

/**
 *
 * @author yoav
 */
public class mainForm extends javax.swing.JFrame implements Observer {

    private Hashtable<String, myTextButton> keyboard;
    private initDataHandler dataHandler = new initDataHandler();
    private XML_Handler xmlHandler = new XML_Handler();
    //this will lock the num+shift num to its position
    private boolean numeralsLock = true;
    private TopBuffer topBuffer = null;
    KeyboardProducer keysProducer;
    private Vector<KeyboardConsumer> consumers = new Vector<KeyboardConsumer>();
    ///////////////////////////////////////////////////////////////////////
    Language lang = null;
    BigInteger totalKeyboards = BigInteger.ZERO;
    long producerTime = -1;
    long consumerTime = -1;

    /** Creates new form mainForm */
    public mainForm() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        keyboardState = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        keyboardPanel = new javax.swing.JPanel();
        ButNum1 = new myTextButton();
        ButNum2 = new myTextButton();
        ButNum3 = new myTextButton();
        ButNum4 = new myTextButton();
        ButNum5 = new myTextButton();
        ButNum6 = new myTextButton();
        ButNum7 = new myTextButton();
        ButNum8 = new myTextButton();
        ButNum9 = new myTextButton();
        ButNum0 = new myTextButton();
        ButA = new myTextButton();
        ButS = new myTextButton();
        ButD = new myTextButton();
        ButL = new myTextButton();
        ButDots = new myTextButton();
        ButJ = new myTextButton();
        ButK = new myTextButton();
        ButF = new myTextButton();
        ButH = new myTextButton();
        ButG = new myTextButton();
        ButI = new myTextButton();
        ButU = new myTextButton();
        ButE = new myTextButton();
        ButW = new myTextButton();
        ButP = new myTextButton();
        ButO = new myTextButton();
        ButQ = new myTextButton();
        ButY = new myTextButton();
        ButT = new myTextButton();
        ButR = new myTextButton();
        ButRightBrackets = new myTextButton();
        ButPipe = new myTextButton();
        ButLeftBrackts = new myTextButton();
        ButQuote = new myTextButton();
        ButZ = new myTextButton();
        ButQuestion = new myTextButton();
        ButM = new myTextButton();
        ButC = new myTextButton();
        ButX = new myTextButton();
        ButSingleDot = new myTextButton();
        ButComma = new myTextButton();
        ButN = new myTextButton();
        ButB = new myTextButton();
        ButV = new myTextButton();
        ButmMinus = new myTextButton();
        ButEq = new myTextButton();
        ButTilda = new myTextButton();
        jPanelKeyboardSearch = new javax.swing.JPanel();
        firstText = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        secondText = new javax.swing.JTextField();
        thirdText = new javax.swing.JTextField();
        jLabelUpdate = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        allRadioBtn = new javax.swing.JRadioButton();
        altRadioBtn = new javax.swing.JRadioButton();
        cntrlRadioBtn = new javax.swing.JRadioButton();
        shiftRadioBtn = new javax.swing.JRadioButton();
        regularRadioBtn = new javax.swing.JRadioButton();
        jButtonCalulate = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jTextLang = new javax.swing.JTextField();
        jButtonLangDir = new javax.swing.JButton();
        jButtoncorpusDir = new javax.swing.JButton();
        jTextCorpus = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanelTabs = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jScrollPaneStatus = new javax.swing.JScrollPane();
        jTextStatus = new javax.swing.JTextArea();
        producerProgress = new JProgressBar(0,100);
        producerProgressBarLabel = new javax.swing.JLabel();
        consumerProgress = new JProgressBar(0, 100);
        cpnsumerProgressBarLabel = new javax.swing.JLabel();
        producerProgressTIme = new javax.swing.JLabel();
        consumerProgressTIme = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        producerRemainingTimeLAbel = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        consumerRemainingTimeLAbel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        myInit();
        jMenu1 = new javax.swing.JMenu();
        fileOpenMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        newMenuItem = new javax.swing.JMenu();
        jMenuItemNewItem = new javax.swing.JMenuItem();
        language = new javax.swing.JMenu();
        load_language = new javax.swing.JMenuItem();
        jMenuNewLang = new javax.swing.JMenuItem();
        jMenuSaveLang = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        keyboardPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Current Kyeboard"));
        keyboardPanel.setPreferredSize(new java.awt.Dimension(1036, 400));

        ButNum1.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum2.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum3.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum4.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum5.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum6.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum7.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum8.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum9.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButNum0.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButA.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButS.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButD.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButL.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButDots.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButJ.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButK.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButF.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        ButF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButFrformed(evt);
            }
        });

        ButH.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButG.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButI.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButU.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButE.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButW.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButP.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButO.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButQ.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButY.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButT.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButR.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButRightBrackets.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButPipe.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButLeftBrackts.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButQuote.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButZ.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButQuestion.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButM.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButC.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButX.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButSingleDot.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButComma.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButN.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButB.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButV.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButmMinus.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButEq.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        ButTilda.setDisabledTextColor(new java.awt.Color(0, 0, 0));

        jPanelKeyboardSearch.setBorder(javax.swing.BorderFactory.createTitledBorder("Keyboard Search"));

        firstText.setEditable(false);
        firstText.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        firstText.setPreferredSize(new java.awt.Dimension(70, 20));
        firstText.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                firstTextMouseClicked(evt);
            }
        });

        jLabel1.setText("Best Keyboards:");

        jLabel2.setText("1)");

        jLabel3.setText("2)");

        jLabel4.setText("3)");

        secondText.setEditable(false);
        secondText.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        secondText.setPreferredSize(new java.awt.Dimension(70, 20));
        secondText.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                secondTextMouseClicked(evt);
            }
        });

        thirdText.setEditable(false);
        thirdText.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        thirdText.setPreferredSize(new java.awt.Dimension(70, 20));
        thirdText.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                thirdTextMouseClicked(evt);
            }
        });

        jLabelUpdate.setText("status..");

        javax.swing.GroupLayout jPanelKeyboardSearchLayout = new javax.swing.GroupLayout(jPanelKeyboardSearch);
        jPanelKeyboardSearch.setLayout(jPanelKeyboardSearchLayout);
        jPanelKeyboardSearchLayout.setHorizontalGroup(
            jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelKeyboardSearchLayout.createSequentialGroup()
                .addGroup(jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelKeyboardSearchLayout.createSequentialGroup()
                        .addGroup(jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(secondText, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(thirdText, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(jLabelUpdate)
                            .addComponent(firstText, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelKeyboardSearchLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(39, 39, 39)))
                .addGap(18, 18, 18))
        );
        jPanelKeyboardSearchLayout.setVerticalGroup(
            jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelKeyboardSearchLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(16, 16, 16)
                .addGroup(jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(firstText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(8, 8, 8)
                .addGroup(jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(secondText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelKeyboardSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(thirdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(jLabelUpdate))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("keyboard view"));

        allRadioBtn.setText("All values");
        allRadioBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                allRadioBtnActionPerformed(evt);
            }
        });

        altRadioBtn.setText("Alt");
        altRadioBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                altRadioBtnActionPerformed(evt);
            }
        });

        cntrlRadioBtn.setText("Cntrl");
        cntrlRadioBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cntrlRadioBtnActionPerformed(evt);
            }
        });

        shiftRadioBtn.setText("Shift");
        shiftRadioBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shiftRadioBtnActionPerformed(evt);
            }
        });

        regularRadioBtn.setSelected(true);
        regularRadioBtn.setText("Regular");
        regularRadioBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                regularRadioBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(allRadioBtn)
                    .addComponent(shiftRadioBtn)
                    .addComponent(regularRadioBtn)
                    .addComponent(cntrlRadioBtn)
                    .addComponent(altRadioBtn)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(regularRadioBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(shiftRadioBtn)
                .addGap(3, 3, 3)
                .addComponent(cntrlRadioBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(altRadioBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(allRadioBtn))
        );

        regularRadioBtn.getAccessibleContext().setAccessibleDescription("regular");

        jButtonCalulate.setText("calculate best Keyboard");
        jButtonCalulate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalulateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout keyboardPanelLayout = new javax.swing.GroupLayout(keyboardPanel);
        keyboardPanel.setLayout(keyboardPanelLayout);
        keyboardPanelLayout.setHorizontalGroup(
            keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(keyboardPanelLayout.createSequentialGroup()
                .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, keyboardPanelLayout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(732, 732, 732)
                                .addComponent(jPanelKeyboardSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(12, 12, 12))
                            .addGroup(keyboardPanelLayout.createSequentialGroup()
                                .addComponent(ButTilda, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(ButQ, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButW, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButE, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButR, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButT, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButY, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButU, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButI, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButO, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButP, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButLeftBrackts, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButRightBrackets, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButPipe, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                                        .addComponent(ButNum1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum4, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum5, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum6, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum7, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum8, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum9, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButNum0, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButmMinus, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ButEq, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addComponent(ButA, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButS, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButD, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButF, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButG, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButH, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButJ, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButK, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButL, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButDots, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButQuote, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(ButZ, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButX, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButC, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ButV, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonCalulate)
                            .addGroup(keyboardPanelLayout.createSequentialGroup()
                                .addComponent(ButB, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButN, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButM, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButComma, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButSingleDot, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButQuestion, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        keyboardPanelLayout.setVerticalGroup(
            keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(keyboardPanelLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButNum1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButTilda, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButNum3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum5, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum6, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum7, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum8, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum4, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum9, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButNum0, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButmMinus, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButEq, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButQ, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButW, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ButE, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButT, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButY, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButU, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButI, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButR, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButO, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButP, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButLeftBrackts, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButRightBrackets, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ButPipe, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ButA, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButS, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ButD, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButG, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButH, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButJ, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButK, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButF, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButL, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButDots, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButQuote, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ButZ, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButX, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(keyboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ButC, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButB, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButN, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButM, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButV, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButComma, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButSingleDot, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ButQuestion, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(26, 26, 26)
                        .addComponent(jButtonCalulate))
                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(keyboardPanelLayout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(jPanelKeyboardSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("keyboard", keyboardPanel);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("corpus init"));

        jLabel6.setText("language file");

        jButtonLangDir.setText("add file");
        jButtonLangDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLangDirActionPerformed(evt);
            }
        });

        jButtoncorpusDir.setText("add dir");
        jButtoncorpusDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtoncorpusDirActionPerformed(evt);
            }
        });

        jLabel5.setText("corpus location");

        jButton1.setText("Index files");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextLang)
                    .addComponent(jTextCorpus, javax.swing.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonLangDir)
                    .addComponent(jButtoncorpusDir))
                .addGap(150, 150, 150))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(351, 351, 351)
                .addComponent(jButton1)
                .addContainerGap(401, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextCorpus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtoncorpusDir)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextLang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonLangDir)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(393, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(214, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Indexer", jPanel3);

        jPanelTabs.setBorder(javax.swing.BorderFactory.createTitledBorder("Status Messages"));

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("show Status");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jTextStatus.setColumns(20);
        jTextStatus.setEditable(false);
        jTextStatus.setRows(5);
        jScrollPaneStatus.setViewportView(jTextStatus);

        jScrollPane2.setViewportView(jScrollPaneStatus);

        javax.swing.GroupLayout jPanelTabsLayout = new javax.swing.GroupLayout(jPanelTabs);
        jPanelTabs.setLayout(jPanelTabsLayout);
        jPanelTabsLayout.setHorizontalGroup(
            jPanelTabsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1310, Short.MAX_VALUE)
            .addGroup(jPanelTabsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCheckBox1)
                .addContainerGap(1219, Short.MAX_VALUE))
        );
        jPanelTabsLayout.setVerticalGroup(
            jPanelTabsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTabsLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        producerProgressBarLabel.setText("Producer:");

        cpnsumerProgressBarLabel.setText("Consumer:");

        producerProgressTIme.setText("update time");

        consumerProgressTIme.setText("update time");

        jLabel7.setText("estimated time remainig:");

        producerRemainingTimeLAbel.setText("remainig time");

        jLabel8.setText("estimated time remainig:");

        consumerRemainingTimeLAbel1.setText("remainig time");

        jMenu1.setText("File");
        jMenu1.setEnabled(false);

        fileOpenMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        fileOpenMenuItem.setText("open  keyboard File");
        fileOpenMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileOpenMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(fileOpenMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setText("save keyboard  File");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(saveMenuItem);

        jMenuBar1.add(jMenu1);

        newMenuItem.setText("manage");

        jMenuItemNewItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItemNewItem.setText("new keboard");
        jMenuItemNewItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemNewItemActionPerformed(evt);
            }
        });
        newMenuItem.add(jMenuItemNewItem);

        jMenuBar1.add(newMenuItem);

        language.setText("Language");

        load_language.setText("Load abstract Language");
        load_language.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                load_languageActionPerformed(evt);
            }
        });
        language.add(load_language);

        jMenuNewLang.setText("new Languge");
        jMenuNewLang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNewLangActionPerformed(evt);
            }
        });
        language.add(jMenuNewLang);

        jMenuSaveLang.setText("save language file");
        jMenuSaveLang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuSaveLangActionPerformed(evt);
            }
        });
        language.add(jMenuSaveLang);

        jMenuBar1.add(language);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanelTabs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1284, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(producerProgressBarLabel)
                            .addComponent(cpnsumerProgressBarLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(consumerProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 523, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(producerProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(consumerProgressTIme)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(consumerRemainingTimeLAbel1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(producerProgressTIme)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(producerRemainingTimeLAbel)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(producerProgressBarLabel)
                    .addComponent(producerProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(producerProgressTIme)
                        .addComponent(producerRemainingTimeLAbel)
                        .addComponent(jLabel8)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cpnsumerProgressBarLabel)
                    .addComponent(consumerProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(consumerProgressTIme)
                        .addComponent(jLabel7)
                        .addComponent(consumerRemainingTimeLAbel1)))
                .addGap(23, 23, 23)
                .addComponent(jPanelTabs, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void myInit() {



        jTextCorpus.setText("C:\\Users\\moshka\\Documents\\NetBeansProjects\\keyBoard2.0\\corpus");
        jTextLang.setText("C:\\Users\\moshka\\Documents\\NetBeansProjects\\keyBoard2.0\\a.xml");




        keyboard = new Hashtable<String, myTextButton>();
        lang = new Language();
        //defaultQwertyInit();
        genericKeyboardInit();
        //Get the jvm heap size.
        long heapSize = Runtime.getRuntime().totalMemory();
        //Print the jvm heap size.
        System.out.println("Heap Size = " + (heapSize / 1024));
        jButtonCalulate.setVisible(false);
        //dataHandler.initKeyCodeMapFromFile("charMap.properties", keyboard);
        if (numeralsLock) {
            dataHandler.initKeyCodeMapFromFile("numeralInit.properties", keyboard);

        }
        refreshRegularDisplay();

        keyboardState.add(regularRadioBtn);
        keyboardState.add(shiftRadioBtn);
        keyboardState.add(altRadioBtn);
        keyboardState.add(cntrlRadioBtn);
        keyboardState.add(allRadioBtn);

        jTextStatus.setEditable(false);
        jScrollPaneStatus.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

            public void adjustmentValueChanged(AdjustmentEvent e) {
                e.getAdjustable().setValue(e.getAdjustable().getMaximum());
                //    jTextStatus.select(jTextStatus.getHeight() + 1000, 0);
            }
        });

        Enumeration<myTextButton> tempKeys = keyboard.elements();
        while (tempKeys.hasMoreElements()) {
            final myTextButton tempbut = tempKeys.nextElement();
            //final String name= tempbut.getRegularLabel();
            tempbut.addKeyListener(new java.awt.event.KeyAdapter() {

                @Override
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    textChangeHandler(evt, tempbut);
                }
            });

        }

        topBuffer = new TopBuffer(10);
        
    }

    private void textChangeHandler(KeyEvent evt, myTextButton butt) {
        // System.out.println("button "+butt.getRegularLabel()+" was");
        if (regularRadioBtn.isSelected()) {
            butt.setRegularLabel(butt.getText());
        } else if (shiftRadioBtn.isSelected()) {
            butt.setShiftLabel(butt.getText());
        } else if (altRadioBtn.isSelected()) {
            butt.setAltLabel(butt.getText());
        } else if (cntrlRadioBtn.isSelected()) {
            butt.setCtrlLabel(butt.getText());
        }


        //System.out.println("button "+butt.getRegularLabel()+" now pressed");
    }

    private void fileOpenMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileOpenMenuItemActionPerformed

        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            clearKeyboard();
            File selectedFile = fileChooser.getSelectedFile();
            System.out.println(selectedFile.getName());
            dataHandler.initKeyCodeMapFromFile(selectedFile.getPath(), keyboard);
            //firstText.setText(selectedFile.getName());
            regularRadioBtn.setSelected(true);
            refreshRegularDisplay();

        }
    }//GEN-LAST:event_fileOpenMenuItemActionPerformed

    private void refreshRegularDisplay() {
        Enumeration<myTextButton> tempKeys = keyboard.elements();
        while (tempKeys.hasMoreElements()) {
            myTextButton tempbut = tempKeys.nextElement();
            tempbut.setText(tempbut.getRegularLabel().trim());
            //   System.out.println(tempbut.getRegularLabel().trim());
            tempbut.setEnabled(true);
        }

    }
    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed


        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showSaveDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            refreshRegularDisplay();
            dataHandler.saveFile(fileChooser.getSelectedFile().toString(), keyboard.elements());
        }


    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void jMenuItemNewItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemNewItemActionPerformed
        clearKeyboard();
    }//GEN-LAST:event_jMenuItemNewItemActionPerformed

    private void load_languageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_load_languageActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            //   Language lang = null;
            clearKeyboard();
            File selectedFile = fileChooser.getSelectedFile();
            System.out.println(selectedFile.getName());
            try {

                lang = (Language) xmlHandler.readfile(selectedFile.getPath());
                xmlHandler.scanAndParseXML(lang, keyboard);
            } catch (Exception ex) {
                Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
            }
            firstText.setText(selectedFile.getName());
            regularRadioBtn.setSelected(true);
            refreshRegularDisplay();

        }
    }//GEN-LAST:event_load_languageActionPerformed

    private void jMenuNewLangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuNewLangActionPerformed
        clearKeyboard();
        lang = new Language();
    }//GEN-LAST:event_jMenuNewLangActionPerformed

    private void jMenuSaveLangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuSaveLangActionPerformed
        Enumeration<myTextButton> tempKeys = keyboard.elements();
        lang = new Language();
        Vector<Symbol> tkeyboard = lang.getSymbolsVect();
        Symbol tempSymbol = null;
        while (tempKeys.hasMoreElements()) {
            myTextButton tempbut = tempKeys.nextElement();

            Character reg = new Character(tempbut.getRegularLabel().charAt(0));
            Character shift = new Character(tempbut.getShiftLabel().charAt(0));
            Character alt = null;
            Character ctrl = null;
            if (!tempbut.getAltLabel().equals("")) {
                alt = new Character(tempbut.getAltLabel().charAt(0));
            }
            if (!tempbut.getCtrlLabel().equals("")) {
                ctrl = new Character(tempbut.getCtrlLabel().charAt(0));
            }

            tempSymbol = new Symbol(reg, shift, alt, ctrl);
            tkeyboard.add(tempSymbol);

            /*tempbut.setBindingsToAlt(false);
            tempbut.setBindingsToCtrl(false);
            tempbut.setBindingsToShift(false);*/
        }
        lang.setSymbolsVect(tkeyboard);
        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showSaveDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            refreshRegularDisplay();
            try {
                xmlHandler.writeToFile(fileChooser.getSelectedFile().toString(), lang);
            } catch (IOException ex) {
                Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_jMenuSaveLangActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed

        jTextStatus.setVisible(jCheckBox1.isSelected());
}//GEN-LAST:event_jCheckBox1ActionPerformed

    private void regularRadioBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_regularRadioBtnActionPerformed
        refreshRegularDisplay();
}//GEN-LAST:event_regularRadioBtnActionPerformed

    private void shiftRadioBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shiftRadioBtnActionPerformed
        Enumeration<myTextButton> tempKeys = keyboard.elements();
        while (tempKeys.hasMoreElements()) {
            myTextButton tempbut = tempKeys.nextElement();
            tempbut.setText(tempbut.getShiftLabel().trim());
            tempbut.setEnabled(true);
        }
}//GEN-LAST:event_shiftRadioBtnActionPerformed

    private void cntrlRadioBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cntrlRadioBtnActionPerformed
        Enumeration<myTextButton> tempKeys = keyboard.elements();
        while (tempKeys.hasMoreElements()) {
            myTextButton tempbut = tempKeys.nextElement();
            tempbut.setText(tempbut.getCtrlLabel().trim());
            tempbut.setEnabled(true);
        }
}//GEN-LAST:event_cntrlRadioBtnActionPerformed

    private void altRadioBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_altRadioBtnActionPerformed
        Enumeration<myTextButton> tempKeys = keyboard.elements();
        while (tempKeys.hasMoreElements()) {
            myTextButton tempbut = tempKeys.nextElement();
            tempbut.setText(tempbut.getAltLabel());
            tempbut.setEnabled(true);
        }
}//GEN-LAST:event_altRadioBtnActionPerformed

    private void allRadioBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allRadioBtnActionPerformed
        Enumeration<myTextButton> tempKeys = keyboard.elements();
        while (tempKeys.hasMoreElements()) {
            myTextButton tempbut = tempKeys.nextElement();
            String bindings = "";
            if (tempbut.isBindingsToAlt()) {
                bindings += "a";
            }

            if (tempbut.isBindingsToCtrl()) {
                bindings += "c";
            }

            if (tempbut.isBindingsToShift()) {
                bindings += "s";
            }

            if (bindings.length() == 0) {
                tempbut.setText(tempbut.getRegularLabel() + " " + tempbut.getShiftLabel() + " " + tempbut.getCtrlLabel() + " " + tempbut.getAltLabel());
            } else {
                tempbut.setText(tempbut.getRegularLabel() + " " + tempbut.getShiftLabel() + " " + tempbut.getCtrlLabel() + " " + tempbut.getAltLabel() + "(" + bindings + ")");
            }

            tempbut.setEnabled(false);
        }
}//GEN-LAST:event_allRadioBtnActionPerformed

    private void ButFrformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButFrformed
        // TODO add your handling code here:
}//GEN-LAST:event_ButFrformed

    private void jButtoncorpusDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtoncorpusDirActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        int returnValue = fileChooser.showOpenDialog(null);
        fileChooser.setDialogType(JFileChooser.DIRECTORIES_ONLY);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            clearKeyboard();
            File selectedFile = fileChooser.getSelectedFile();
            jTextCorpus.setText(selectedFile.toString());
            refreshRegularDisplay();
        }
    }//GEN-LAST:event_jButtoncorpusDirActionPerformed

    private void jButtonLangDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLangDirActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        int returnValue = fileChooser.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            clearKeyboard();
            File selectedFile = fileChooser.getSelectedFile();
            jTextLang.setText(selectedFile.toString());
            refreshRegularDisplay();

        }
    }//GEN-LAST:event_jButtonLangDirActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        String corpDir = jTextCorpus.getText();
        String langFile = jTextLang.getText();
        if (corpDir == null || corpDir.equals("") || langFile == null || langFile.equals("")) {
            jTextStatus.append("must choose file and dir to run indexer\n");
            return;
        }
        // Language lang = null;
        try {
            lang = (Language) xmlHandler.readfile(langFile);
        } catch (Exception ex) {
            Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (lang == null) {
            jTextStatus.append("language file parsing failed\n");
            return;
        }

        Indexer indexer = new Indexer(lang, corpDir);
        indexer.addObserver(this);
        indexer.start();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButtonCalulateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCalulateActionPerformed
        if (jButtonCalulate.getText().equals("pause")) {
            jButtonCalulate.setText("calculate best Keyboard");
            keysProducer.stopAndSave();
            topBuffer.stopAndSave();

            for (KeyboardConsumer kbc : consumers) {
                kbc.stopRun();
            }

        } else if (jButtonCalulate.getText().equals("calculate best Keyboard")) {

            jPanelTabs.setVisible(false);
            Properties keyPriority = new Properties();
            try {
                keyPriority.load(new FileInputStream(new File("keyPriorityGeneric.properties")));
            } catch (IOException ex) {
                Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
            }
            Language selectedLanguage = null;
            try {
                selectedLanguage = (Language) xmlHandler.readfile(jTextLang.getText());
            } catch (Exception ex) {
                Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
            }

            SynchronizedBuffer sb = new SynchronizedBuffer();
            keysProducer = new KeyboardProducer(sb, selectedLanguage, keyPriority);
            keysProducer.setGeneric(true);
//        kbp.setGeneric(false);
            keysProducer.addObserver(this);

            for (int i = 0; i < 3; i++) {

                KeyboardConsumer keysConsumer = new KeyboardConsumer(sb, topBuffer, "consumerCorpus", selectedLanguage);
                keysConsumer.addObserver(this);
                consumers.add(keysConsumer);
                keysConsumer.setName("KC" + i);
                keysConsumer.start();
            }
            topBuffer.addObserver(this);
            keysProducer.start();
//            jButtonCalulate.setEnabled(false);
            jButtonCalulate.setText("pause");
            jScrollPaneStatus.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

                public void adjustmentValueChanged(AdjustmentEvent e) {
                    e.getAdjustable().setValue(e.getAdjustable().getMaximum());
                }
            });
            producerProgress.setValue(0);
            producerProgress.setStringPainted(true);
            producerProgress.setIndeterminate(true);

            consumerProgress.setValue(0);
            consumerProgress.setStringPainted(true);
            consumerProgress.setIndeterminate(true);
            recive(topBuffer, null);
        }

    }//GEN-LAST:event_jButtonCalulateActionPerformed

    private void updateKeyboardCandidateUI(Symbol[][] candidate) {
        Vector<Symbol> symbols = lang.getSymbolsSortet();
        //   Iterator<Symbol> it = candidate.iterator();
        //    Symbol symbol = (Symbol) it.next();

        //------------------------------------------------------------------------------first row init-----------------------------------------------------------------------------
        Symbol[] row = candidate[0];
        for (int i = 1; i <= 13; i++) {
            //001->013
            String result = XML_Handler.intToString(i, 3, '0');
            XML_Handler.updateButt(keyboard, result, row[i - 1]);
        }
        //------------------------------------------------------------------------------second row init-----------------------------------------------------------------------------
        row = candidate[1];
        for (int i = 1; i <= 13; i++) {
            //101->113
            String result = "1" + XML_Handler.intToString(i, 2, '0');
            XML_Handler.updateButt(keyboard, result, row[i - 1]);
            //System.out.println(result);
        }
        //------------------------------------------------------------------------------3rd row init-----------------------------------------------------------------------------
        row = candidate[2];
        for (int i = 1; i <= 11; i++) {
            //201->211
            String result = "2" + XML_Handler.intToString(i, 2, '0');
            XML_Handler.updateButt(keyboard, result, row[i - 1]);
            //System.out.println(result);
        }
        //------------------------------------------------------------------------------4th row init-----------------------------------------------------------------------------
        row = candidate[3];
        for (int i = 1; i <= 10; i++) {
            //301->310
            String result = "3" + XML_Handler.intToString(i, 2, '0');
            XML_Handler.updateButt(keyboard, result, row[i - 1]);
            //System.out.println(result);
        }

    }

    private void firstTextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_firstTextMouseClicked
        // jTextStatus.append("pressed\n");

        KeyboardCandidate[] candidates = topBuffer.getTop();
        updateKeyboardCandidateUI(candidates[0].getKeys());
        refreshRegularDisplay();
        System.out.println("first");
    }//GEN-LAST:event_firstTextMouseClicked

    private void secondTextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_secondTextMouseClicked
        KeyboardCandidate[] candidates = topBuffer.getTop();
        updateKeyboardCandidateUI(candidates[1].getKeys());
        refreshRegularDisplay();
        System.out.println("sec");
    }//GEN-LAST:event_secondTextMouseClicked

    private void thirdTextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_thirdTextMouseClicked
        KeyboardCandidate[] candidates = topBuffer.getTop();
        updateKeyboardCandidateUI(candidates[2].getKeys());
        refreshRegularDisplay();
        System.out.println("third");
    }//GEN-LAST:event_thirdTextMouseClicked

    private void clearKeyboard() {
        Enumeration<myTextButton> tempKeys = keyboard.elements();
        while (tempKeys.hasMoreElements()) {
            myTextButton tempbut = tempKeys.nextElement();
            tempbut.setText("");
            tempbut.setAltLabel("");
            tempbut.setCtrlLabel("");
            tempbut.setShiftLabel("");
            tempbut.setRegularLabel("");
            tempbut.setBindingsToAlt(false);
            tempbut.setBindingsToCtrl(false);
            tempbut.setBindingsToShift(false);
            tempbut.setEnabled(true);
        }

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new mainForm().setVisible(true);
            }
        });
    }

    private void genericKeyboardInit() {
        //------------------------------------------------------------------------------first row init-----------------------------------------------------------------------------
        keyboard.put("001", (myTextButton) ButTilda);
        keyboard.put("002", (myTextButton) ButNum1);
        keyboard.put("003", (myTextButton) ButNum2);
        keyboard.put("004", (myTextButton) ButNum3);
        keyboard.put("005", (myTextButton) ButNum4);
        keyboard.put("006", (myTextButton) ButNum5);
        keyboard.put("007", (myTextButton) ButNum6);
        keyboard.put("008", (myTextButton) ButNum7);
        keyboard.put("009", (myTextButton) ButNum8);
        keyboard.put("010", (myTextButton) ButNum9);
        keyboard.put("011", (myTextButton) ButNum0);
        keyboard.put("012", (myTextButton) ButEq);
        keyboard.put("013", (myTextButton) ButmMinus);
        //------------------------------------------------------------------------------second row init-----------------------------------------------------------------------------
        keyboard.put("101", (myTextButton) ButQ);
        keyboard.put("102", (myTextButton) ButW);
        keyboard.put("103", (myTextButton) ButE);
        keyboard.put("104", (myTextButton) ButR);
        keyboard.put("105", (myTextButton) ButT);
        keyboard.put("106", (myTextButton) ButY);
        keyboard.put("107", (myTextButton) ButU);
        keyboard.put("108", (myTextButton) ButI);
        keyboard.put("109", (myTextButton) ButO);
        keyboard.put("110", (myTextButton) ButP);
        keyboard.put("111", (myTextButton) ButLeftBrackts);
        keyboard.put("112", (myTextButton) ButRightBrackets);
        keyboard.put("113", (myTextButton) ButPipe);
        //------------------------------------------------------------------------------3rd row init-----------------------------------------------------------------------------
        keyboard.put("201", (myTextButton) ButA);
        keyboard.put("202", (myTextButton) ButS);
        keyboard.put("203", (myTextButton) ButD);
        keyboard.put("204", (myTextButton) ButF);
        keyboard.put("205", (myTextButton) ButG);
        keyboard.put("206", (myTextButton) ButH);
        keyboard.put("207", (myTextButton) ButJ);
        keyboard.put("208", (myTextButton) ButK);
        keyboard.put("209", (myTextButton) ButL);
        keyboard.put("210", (myTextButton) ButDots);
        keyboard.put("211", (myTextButton) ButQuote);
        //------------------------------------------------------------------------------4th row init-----------------------------------------------------------------------------
        keyboard.put("301", (myTextButton) ButZ);
        keyboard.put("302", (myTextButton) ButX);
        keyboard.put("303", (myTextButton) ButC);
        keyboard.put("304", (myTextButton) ButV);
        keyboard.put("305", (myTextButton) ButB);
        keyboard.put("306", (myTextButton) ButN);
        keyboard.put("307", (myTextButton) ButM);
        keyboard.put("308", (myTextButton) ButComma);
        keyboard.put("309", (myTextButton) ButSingleDot);
        keyboard.put("310", (myTextButton) ButQuestion);


    }

    private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Calendar date = Calendar.getInstance();
        return dateFormat.format(date.getTime());
    }

    public void recive(Object sender, String msg) {
        if (sender instanceof KeyboardProducer) {
            handleProducerMsg(msg);
        } else if (sender instanceof KeyboardConsumer) {
            handleConsumerMsg(msg);
        } else if (sender instanceof Indexer) {
            handleIndexerMsg(msg);
        } else if (sender instanceof TopBuffer) {
            handleTOPMsg(msg);
        }
        

    }

    private void updateStatus(String msg) {
        if (jPanelTabs.isVisible()) {
            jTextStatus.append(msg + "\n");
        }
    }

    private void handleTOPMsg(String msg) {
        System.out.println("updateTop");
        KeyboardCandidate[] candidates = topBuffer.getTop();
        if (candidates != null && candidates.length >= 3) {
            if (candidates[0] != null) {
                firstText.setText("ID:" + candidates[0].getId().toString() + " score:" + candidates[0].getScore());
            }
            if (candidates[1] != null) {
                secondText.setText("ID:" + candidates[1].getId().toString() + " score:" + candidates[1].getScore());
            }
            if (candidates[2] != null) {
                thirdText.setText("ID:" + candidates[2].getId().toString() + " score:" + candidates[2].getScore());
            }
        }

    }

    private void handleProducerMsg(String msg) {
        if (msg.equals(KeyboardProducer.FINISH)) {
            for (KeyboardConsumer keyboardConsumer : consumers) {
                keyboardConsumer.stopRun();
            }
        } else if (msg.startsWith(KeyboardProducer.PRODUCED)) {

            BigInteger val = new BigInteger(msg.split(":")[1]);
//            System.out.println("ID = "+ val);
            BigInteger total = new BigInteger(msg.split(":")[2]);
            if (this.totalKeyboards.equals(BigInteger.ZERO)) {
                this.totalKeyboards = total;
                producerProgress.setString(NumberFormat.getNumberInstance().format(totalKeyboards));
            }
            BigInteger percent = val.divide(this.totalKeyboards).multiply(new BigInteger("100"));
            BigInteger left = this.totalKeyboards.subtract(val);
            if (percent.intValue() != 0) {
                if (producerProgress.isIndeterminate()) {
                    producerProgress.setIndeterminate(false);
                }
                producerProgress.setValue(percent.intValue());
                if (left.compareTo(new BigInteger(String.valueOf(keysProducer.getUpdateCounter()))) < 0) {
                    keysProducer.setUpdateCounter(keysProducer.getUpdateCounter() / 10);
                }
            }
            producerProgress.setString(NumberFormat.getInstance().format(left));
            producerProgressTIme.setText(getDateTime());

            if (producerTime < 0) {
                producerTime = System.currentTimeMillis();
            } else {
                producerTime = System.currentTimeMillis() - producerTime;
                BigInteger timeValue = new BigInteger(String.valueOf(producerTime)).multiply(left);
                BigInteger[] ans = new BigInteger[2];
                ans = timeValue.divideAndRemainder(new BigInteger("86400000"));
                BigInteger days = ans[0];
                timeValue = ans[1];
                ans = timeValue.divideAndRemainder(new BigInteger("3600000"));
                BigInteger hours = ans[0];
                timeValue = ans[1];
                ans = timeValue.divideAndRemainder(new BigInteger("60000"));
                BigInteger minutes = ans[0];
                timeValue = ans[1];
                ans = timeValue.divideAndRemainder(new BigInteger("1000"));
                BigInteger seconds = ans[0];
                producerRemainingTimeLAbel.setText(days.toString() + ":" + hours.toString() + ":" + minutes.toString() + ":" + seconds.toString());
                producerTime = -1;
            }


        }
        updateStatus("producer : " + msg);
    }

    private void handleConsumerMsg(String msg) {
        if (msg.startsWith(KeyboardConsumer.CALCULATED) && !this.totalKeyboards.equals(BigInteger.ZERO)) {
            BigInteger val = new BigInteger(msg.split(":")[1]).divide(totalKeyboards).multiply(new BigInteger("100"));
            consumerProgress.setString(val.toString() + "%");
            consumerProgressTIme.setText(getDateTime());
            consumerProgress.setValue(val.intValue());
            if (val.intValue() > 0) {
                consumerProgress.setIndeterminate(false);
            }
        } else if (msg.startsWith(KeyboardConsumer.FINISH)) {
        }

        jLabelUpdate.setText("last update:" + getDateTime());

        updateStatus("consumer : " + msg);
    }

    private void handleIndexerMsg(String msg) {
        if (msg.startsWith(Indexer.DONE)) {
            jScrollPaneStatus.setVerticalScrollBar(new JScrollBar());
            jButtonCalulate.setVisible(true);
            xmlHandler.scanAndParseXML(lang, keyboard);
            jTabbedPane1.setSelectedIndex(0);
            //    jPanelKeyboardSearch.setEnabled(true);
            refreshRegularDisplay();
            try {
                xmlHandler.writeToFile(jTextLang.getText(), lang);
            } catch (IOException ex) {
                Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        updateStatus("indexer : " + msg);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ButA;
    private javax.swing.JTextField ButB;
    private javax.swing.JTextField ButC;
    private javax.swing.JTextField ButComma;
    private javax.swing.JTextField ButD;
    private javax.swing.JTextField ButDots;
    private javax.swing.JTextField ButE;
    private javax.swing.JTextField ButEq;
    private javax.swing.JTextField ButF;
    private javax.swing.JTextField ButG;
    private javax.swing.JTextField ButH;
    private javax.swing.JTextField ButI;
    private javax.swing.JTextField ButJ;
    private javax.swing.JTextField ButK;
    private javax.swing.JTextField ButL;
    private javax.swing.JTextField ButLeftBrackts;
    private javax.swing.JTextField ButM;
    private javax.swing.JTextField ButN;
    private javax.swing.JTextField ButNum0;
    private javax.swing.JTextField ButNum1;
    private javax.swing.JTextField ButNum2;
    private javax.swing.JTextField ButNum3;
    private javax.swing.JTextField ButNum4;
    private javax.swing.JTextField ButNum5;
    private javax.swing.JTextField ButNum6;
    private javax.swing.JTextField ButNum7;
    private javax.swing.JTextField ButNum8;
    private javax.swing.JTextField ButNum9;
    private javax.swing.JTextField ButO;
    private javax.swing.JTextField ButP;
    private javax.swing.JTextField ButPipe;
    private javax.swing.JTextField ButQ;
    private javax.swing.JTextField ButQuestion;
    private javax.swing.JTextField ButQuote;
    private javax.swing.JTextField ButR;
    private javax.swing.JTextField ButRightBrackets;
    private javax.swing.JTextField ButS;
    private javax.swing.JTextField ButSingleDot;
    private javax.swing.JTextField ButT;
    private javax.swing.JTextField ButTilda;
    private javax.swing.JTextField ButU;
    private javax.swing.JTextField ButV;
    private javax.swing.JTextField ButW;
    private javax.swing.JTextField ButX;
    private javax.swing.JTextField ButY;
    private javax.swing.JTextField ButZ;
    private javax.swing.JTextField ButmMinus;
    private javax.swing.JRadioButton allRadioBtn;
    private javax.swing.JRadioButton altRadioBtn;
    private javax.swing.JRadioButton cntrlRadioBtn;
    private javax.swing.JProgressBar consumerProgress;
    private javax.swing.JLabel consumerProgressTIme;
    private javax.swing.JLabel consumerRemainingTimeLAbel1;
    private javax.swing.JLabel cpnsumerProgressBarLabel;
    private javax.swing.JMenuItem fileOpenMenuItem;
    private javax.swing.JTextField firstText;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonCalulate;
    private javax.swing.JButton jButtonLangDir;
    private javax.swing.JButton jButtoncorpusDir;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelUpdate;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItemNewItem;
    private javax.swing.JMenuItem jMenuNewLang;
    private javax.swing.JMenuItem jMenuSaveLang;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanelKeyboardSearch;
    private javax.swing.JPanel jPanelTabs;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPaneStatus;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextCorpus;
    private javax.swing.JTextField jTextLang;
    private javax.swing.JTextArea jTextStatus;
    private javax.swing.JPanel keyboardPanel;
    private javax.swing.ButtonGroup keyboardState;
    private javax.swing.JMenu language;
    private javax.swing.JMenuItem load_language;
    private javax.swing.JMenu newMenuItem;
    private javax.swing.JProgressBar producerProgress;
    private javax.swing.JLabel producerProgressBarLabel;
    private javax.swing.JLabel producerProgressTIme;
    private javax.swing.JLabel producerRemainingTimeLAbel;
    private javax.swing.JRadioButton regularRadioBtn;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JTextField secondText;
    private javax.swing.JRadioButton shiftRadioBtn;
    private javax.swing.JTextField thirdText;
    // End of variables declaration//GEN-END:variables
}
